<?php
function jump($msg, $url) {
    echo '<script>
            alert("'. $msg .'");
            window.location.href="' . $url . '"
        </script>';
}
// /lesson04/doLogin.php?username=123&password=234
// 全局数组 $_GET  $_POST  处理数据时，用哪一个取决于form表单提交方式
//print_r($_GET);

// 通用获取参数的方式
//$username = isset($_GET['username']) ? trim($_GET['username']) : '';
//$password = isset($_GET['password']) ? $_GET['password'] : '';

$username = isset($_POST['username']) ? trim($_POST['username']) : '';
$password = isset($_POST['password']) ? $_POST['password'] : '';

if (empty($username) || empty($password)) {
    jump('用户名或者密码不能为空', '/lesson04/login.php');
}

// 模拟查询数据库, 通过用户名从数据库中获取$user
$user = [
    'username' => $username,
    'password' => '123456'
];
if ($password != $user['password']) {
    jump('密码填写错误，登录失败', '/lesson04/login.php');
}

// 登录成功
jump('登录成功', '/lesson04/center.php'); //center.php not found



